/**

 @Name：layuiAdmin 主页控制台
 @Author：贤心
 @Site：http://www.layui.com/admin/
 @License：GPL-2
    
 */


layui.define(function(exports) {
	/*
	  下面通过 layui.use 分段加载不同的模块，实现不同区域的同时渲染，从而保证视图的快速呈现
	*/
	//区块轮播切换
	layui.use(['carousel', 'zlContext'], function() {
		var $ = layui.$
			, carousel = layui.carousel
			, device = layui.device();

		//轮播切换
		$('.layadmin-carousel').each(function() {
			var othis = $(this);
			carousel.render({
				elem: this
				, width: '100%'
				, arrow: 'none'
				, interval: othis.data('interval')
				, autoplay: othis.data('autoplay') === true
				, trigger: (device.ios || device.android) ? 'click' : 'hover'
				, anim: othis.data('anim')
			});
		});
		//element.render('progress');
	});


	//数据概览
	layui.use(['carousel', 'zlContext'], function() {
		var $ = layui.$
			, carousel = layui.carousel
			, echarts = layui.echarts
			, zlContext = layui.zlContext
			, showdata
			, options = [];

		zlContext.get(layui.cache['contentPath'] + "/core/datact/queryBrowser", null,
			function(data) {
				if (data.state == 'OK') {
					showdata = data.obj;
					if (showdata) {
						options = [
							//访客浏览器分布
							{
								title: {
									text: '访客浏览器分布',
									x: 'center',
									textStyle: {
										fontSize: 14
									}
								},
								tooltip: {
									trigger: 'item',
									formatter: "{a} <br/>{b} : {c} ({d}%)"
								},
								legend: {
									orient: 'vertical',
									x: 'left',
									data: showdata.title
								},
								series: [{
									name: '访问来源',
									type: 'pie',
									radius: '55%',
									center: ['50%', '50%'],
									data: showdata.value
								}]
							},
						];
						renderDataView(0);
					} else {
						$('#LAY-index-dataview').empty();
						zlContext.noData($('#LAY-index-dataview'), false);
					}

				} else {
					zlContext.errorMsg(data.msg);
				}
			});

		//没找到DOM，终止执行
		// if (!elemDataView[0]) return;



		// renderDataView(0);

		//监听数据概览轮播
		var carouselIndex = 0;
		carousel.on('change(LAY-index-dataview)', function(obj) {
			renderDataView(carouselIndex = obj.index);
		});

		//   //监听侧边伸缩
		//   layui.admin.on('side', function(){
		//     setTimeout(function(){
		//       renderDataView(carouselIndex);
		//     }, 300);
		//   });

		//   //监听路由
		//   layui.admin.on('hash(tab)', function(){
		//     layui.router().path.join('') || renderDataView(carouselIndex);
		//   });
	});

	exports('console', {})
});